package com.ggb.reactive.config

import com.ggb.reactive.properties.AliOssProperties
import com.ggb.reactive.utils.AliOssUtil
import lombok.RequiredArgsConstructor
import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
@RequiredArgsConstructor
class OssConfiguration(private val aliOssProperties: AliOssProperties) {

    private val log = LoggerFactory.getLogger(OssConfiguration::class.java)

    @Bean
    @ConditionalOnMissingBean
    fun aliOssUtil(): AliOssUtil {
        log.info("开始创建阿里云文件上传工具类对象{}", aliOssProperties)
        return AliOssUtil(
            endpoint = aliOssProperties.endpoint!!,
            accessKeyId = aliOssProperties.accessKeyId!!,
            accessKeySecret = aliOssProperties.accessKeySecret!!,
            bucketName = aliOssProperties.bucketName!!
        )
    }
}